

var myTurn = true;
var simPlays = false;
var turnIndex = 0;

var players = {
		1: 'Matt',
		2: 'Mark',
		3: 'John',
		4: 'Bill'
	};


var score1 = 0;
var score2 = 0;
var score3 = 0;
var score4 = 0;








function endTurn() {
	
	myTurn = false;
	
	simulateTurns();
}

function nextRound() {
	Ext.getCmp('nextRoundButton').enable();
	
	myTurn = true;
	game.nextTurn();
}

function submitMayICards(id, details) {
	console.log(getName(id)+' May I: '+JSON.stringify(details.card));
}

function getOpponentIndex(id) {
	return (parseInt(id)-2);
}

function submitMayIRequest() {
	
}

function submitScores(scores) {
	var opp = getOpponents();
	
	var scorecard = {};
	scorecard[getMyId()] = scores[0];
	scorecard['2'] = scores[1];
	scorecard['3'] = scores[2];
	scorecard['4'] = scores[3];
		
	game.updateScores(scorecard);
}

function simulateTurns() {
	
	turnIndex++;
	game.nextTurn();
	
	
	var draw = {};
	draw.id = '2';
	draw.from = 'discardpile';
	draw.card = {
		suit: 'Hearts',
		number: '5'
	};
	game.drewCard(draw);
		
	var c = game.hands[1].items.items[0];
	var discard = {};
	discard.card = {
		suit: c.suit,
		number: c.number
	};
	discard.plays = simulatePlays(2);
	game.discardedCard(discard);
	
	turnIndex++;
	game.nextTurn();
	
	/*
	draw = {};
	draw.id = '1';
	draw.from = 'discardpile';
	draw.card = {
		suit: 'Hearts',
		number: '5'
	};
	game.drewCard(draw);
	
	draw = {};
	draw.id = '1';
	draw.from = 'unuseddeck';
	draw.card = {
		suit: 'Hearts',
		number: '5'
	};
	game.drewCard(draw);
	*/
	
	draw = {};
	draw.id = '3';
	draw.from = 'unuseddeck';
	draw.card = {
		suit: 'Hearts',
		number: '5'
	};
	game.drewCard(draw);
		
	c = game.hands[2].items.items[0];
	discard = {};
	discard.card = {
		suit: c.suit,
		number: c.number
	};
	discard.plays = simulatePlays(3);
	game.discardedCard(discard);
	
	turnIndex++;
	game.nextTurn();
	
	
	draw = {};
	draw.id = '4';
	draw.from = 'discardpile';
	draw.card = {
		suit: 'Hearts',
		number: '5'
	};
	game.drewCard(draw);
		
	c = game.hands[3].items.items[0];
	discard = {};
	discard.card = {
		suit: c.suit,
		number: c.number
	};
	discard.plays = simulatePlays(4);
	game.discardedCard(discard);
	
	turnIndex = 0;
	myTurn = true;
	game.nextTurn();
	
}

function simulatePlays(id) {
	
	var p = [];
	
	if (simPlays == true) {
		var areas = game.oppplayareas[id-2];
		
		var cards = game.hands[id-2].items.items;
		
		
		p[0] = {
			type: 0,
			pIndex: 0,
			aIndex: 0,
			cards: [{
				suit: cards[1].suit,
				number: cards[1].number
			},{
				suit: cards[2].suit,
				number: cards[2].number
			},{
				suit: cards[3].suit,
				number: cards[3].number
			}]
		};
		
		p[1] = {
				type: 1,
				pIndex: 0,
				aIndex: 1,
				cards: [{
					suit: cards[4].suit,
					number: cards[4].number
				},{
					suit: cards[5].suit,
					number: cards[5].number
				},{
					suit: cards[6].suit,
					number: cards[6].number
				},{
					suit: cards[7].suit,
					number: cards[7].number
				}]
			};
		
	}
	
	return p;
}

function getMyId() {
	return '1';
}

function getName(id) {
	return players[id];
}

function getTurnIndex() {
	return turnIndex;
}

function getTurnName() {
	return 'Matt';
}

function getNumP() {
	return 4;
}

function drawCard(details) {
	console.log('Drew Card from '+details.from+': '+JSON.stringify(details.card));
}

function discard(details) {
	console.log('Discarded: '+JSON.stringify(details));	
}

function isTurn() {
	return myTurn;
}

function getOpponents() {
	var opp = [];
	opp[0] = {
		id: '2',
		name: 'Mark'
	};
	opp[1] = {
		id: '3',
		name: 'John'
	};
	opp[2] = {
		id: '4',
		name: 'Bill'
	};
	return opp;
}